package com.spic.business.train.trainUser.service.impl;

import com.spic.business.train.trainUser.domain.TrainUser;
import com.spic.business.train.trainUser.mapper.TrainUserMapper;
import com.spic.business.train.trainUser.service.ITrainUserService;
import com.spic.common.security.utils.cache.UserCacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 培训用户Service业务层处理
 * 
 * @author spic
 * @date 2021-10-15
 */
@Service
public class TrainUserServiceImpl implements ITrainUserService 
{
    @Autowired
    private TrainUserMapper trainUserMapper;

    /**
     * 查询培训用户
     * 
     * @param id 培训用户主键
     * @return 培训用户
     */
    @Override
    public TrainUser selectTrainUserById(Long id)
    {
        return trainUserMapper.selectTrainUserById(id);
    }

    /**
     * 查询培训用户列表
     * 
     * @param trainUser 培训用户
     * @return 培训用户
     */
    @Override
    public List<TrainUser> selectTrainUserList(TrainUser trainUser)
    {
        List<TrainUser> trainUsers=trainUserMapper.selectTrainUserList(trainUser);
        trainUsers.forEach(trainUser1 -> {
            try {
                trainUser1.setUserName(UserCacheUtils.getValue(trainUser1.getUserId()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        return trainUsers;
    }

    /**
     * 新增培训用户
     * 
     * @param trainUser 培训用户
     * @return 结果
     */
    @Override
    public int insertTrainUser(TrainUser trainUser)
    {
        return trainUserMapper.insertTrainUser(trainUser);
    }

    /**
     * 修改培训用户
     * 
     * @param trainUser 培训用户
     * @return 结果
     */
    @Override
    public int updateTrainUser(TrainUser trainUser)
    {
        return trainUserMapper.updateTrainUser(trainUser);
    }

    /**
     * 批量删除培训用户
     * 
     * @param ids 需要删除的培训用户主键
     * @return 结果
     */
    @Override
    public int deleteTrainUserByIds(String[] ids)
    {
        return trainUserMapper.deleteTrainUserByIds(ids);
    }

    /**
     * 删除培训用户信息
     * 
     * @param id 培训用户主键
     * @return 结果
     */
    @Override
    public int deleteTrainUserById(String id)
    {
        return trainUserMapper.deleteTrainUserById(id);
    }
    /**
     * 批量新增培训用户
     *
     * @param trainUsers 培训用户集合
     * @return 结果
     */
    public int insertTrainUsers(List<TrainUser> trainUsers){
        return trainUserMapper.insertTrainUsers(trainUsers);
    }
    public TrainUser  selectTrainUserByTrainIdAndUserId(String trainInfoId,  Long userId){
        return  trainUserMapper.selectTrainUserByTrainIdAndUserId(trainInfoId,userId);
    }
}
